package com.ruoyi.business.service;


import com.ruoyi.business.domain.CivilServantsList;
import com.ruoyi.business.domain.vo.CivilServantsListVo;
import com.ruoyi.business.mapper.CivilServantsListMapper;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static cn.hutool.crypto.CipherMode.encrypt;
import static com.ruoyi.business.utils.DES.decrypt;
import static com.ruoyi.business.utils.DES.encrypt;
//import static com.ruoyi.business.utils.RSAUtil.decrypt;


@Service
public class CivilServantsListService {

    private static final String KEY = "12345678";

    @Autowired
    CivilServantsListMapper civilServantsListMapper;

    public List<CivilServantsListVo> getList(Long civilServantsId, String prosCons) throws Exception {
        List<CivilServantsListVo> list = civilServantsListMapper.getList(civilServantsId, prosCons);
        for (CivilServantsListVo civilServantsListVo : list) {
            String workList = civilServantsListVo.getWorkList();
//            civilServantsListVo.setWorkList(decrypt(workList));
            civilServantsListVo.setWorkList(decrypt(workList,KEY));
        }
        return list;
    }

    public void delete(Long id) {
        int deleteResult = civilServantsListMapper.delete(id);
        if (deleteResult==0){
            throw new RuntimeException("机关公务员清单删除失败");
        }
    }

    public void add(CivilServantsList civilServantsList) throws Exception {
        String workList = civilServantsList.getWorkList();
        civilServantsList.setWorkList(encrypt(workList,KEY));
        int addResult = civilServantsListMapper.insert(civilServantsList);
        if (addResult==0){
            throw new RuntimeException("机关公务员清单新增失败");
        }
    }

    public void update(CivilServantsList civilServantsList) throws Exception {
        String workList = civilServantsList.getWorkList();
        civilServantsList.setWorkList(encrypt(workList,KEY));
        int updateResult = civilServantsListMapper.update(civilServantsList);
        if (updateResult==0){
            throw new RuntimeException("机关公务员清单修改失败");
        }
    }
}
